package com.bupt.smart.ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bupt.smart.model.RepairRequest;
import com.bupt.smart.smart.R;
import com.bupt.smart.ui.activity.RepairDetailsActivity;
import com.marshalchen.ultimaterecyclerview.UltimateViewAdapter;

import org.w3c.dom.Text;

import java.util.List;

/**
 * Created by ght on 2016/4/6.
 */
public class RepairRecyclerViewAdapter extends RecyclerView.Adapter<RepairRecyclerViewAdapter.RepairViewHolder>{

    private Context mContext;
    private List<RepairRequest> mData;

    public RepairRecyclerViewAdapter(Context context, List<RepairRequest> datas) {

        this.mContext = context;
        mData = datas;
    }

    @Override
    public RepairViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.repair_recyclerview_item, parent, false);

        return new RepairViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RepairViewHolder holder, int position) {
        holder.title.setText(mData.get(position).getTitle());
        holder.date.setText(mData.get(position).getDate().toString());
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    public class RepairViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
        TextView title;
        TextView date;

        public RepairViewHolder(View v) {
            super(v);
            title = (TextView) v.findViewById(R.id.repair_rv_item_title);
            date = (TextView) v.findViewById(R.id.repair_rv_item_date);
            v.setOnClickListener(this);
        }

        @Override
        public void onClick(View v) {
            int itemPosition = getAdapterPosition();
            Intent intent = new Intent(mContext, RepairDetailsActivity.class);
            intent.putExtra("repairRequest", mData.get(itemPosition));
            mContext.startActivity(intent);
        }
    }
}
